<template>
  <div class="home">
    <div class="home-container">
      <div class="home-menu">
        <div class="menu-header">
          <img class="user-avatar" src="@/assets/images/profile.jpg"/>
          <div class="user-profile">
            <div class="user-profile-main">
              <div class="user-profile-header">
                <img class="user-avatar" src="@/assets/images/profile.jpg"/>
                <div>{{ currentUser.name }}</div>
              </div>
              <div class="user-profile-info">
                <div class="user-profile-info-title">邮箱</div>
                <div>{{ currentUser.email }}</div>
              </div>
              <div class="user-profile-info">
                <div class="user-profile-info-title">昵称</div>
                <div>{{ currentUser.nickName }}</div>
              </div>
            </div>
          </div>
        </div>
        <div class="menu-box">
          <div class="menu-list">
            <div  class="menu-item" @click="componentName='conversations'"  >
              <i class="iconfont icon-zaixiankefu"></i>
            </div>
            <div  class="menu-item"  @click="componentName='contacts'" >
              <i class="iconfont icon-haoyou"></i>
            </div>
            <div  class="menu-item"  @click="" >

              <el-col :span="1.5">
                <el-button
                  style="border: none;background-color: #F7F7F7;"
                  size="mini"
                  @click="handleAdd"
                  v-hasPermi="['message:group:add']"
                >  <i class="iconfont icon-gengduo"></i></el-button>
              </el-col>
            </div>
          </div>
          <div class="exit">
            <i class="iconfont icon-h" @click="logout"></i>
          </div>
        </div>
      </div>
      <div class="home-main">
        <Component :is="componentName"></Component>
      </div>
    </div>
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="群名称" prop="groupName">
          <el-input v-model="form.groupName" placeholder="请输入群名称" />
        </el-form-item>
        <el-form-item label="群头像" prop="groupAvatar">
          <image-upload v-model="form.groupAvatar"/>
        </el-form-item>
        <el-form-item label="群描述" prop="groupDescription">
          <el-input v-model="form.groupDescription" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>

import Conversations from "@/views/message/message/Conversations";
import Contacts from "@/views/message/message/Contacts";
import {addGroup, updateGroup} from "@/api/message/group";

  export default {
    components: {Conversations,Contacts},
    data() {
      return {
        componentName:"conversations",
        currentUser: null,
        unreadAmount: null,
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 表单参数
        form: {},
        // 表单校验
        rules: {
        }
      };
    },
    created() {
      this.currentUser = this.$store.state.user.user;
    },
    methods: {
      // 表单重置
      reset() {
        this.form = {
          id: null,
          groupName: null,
          groupAvatar: null,
          createBy: null,
          groupDescription: null,
          createTime: null
        };
        this.resetForm("form");
      },
      logout(){},
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加群";
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateGroup(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addGroup(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
    },
  };
</script>

<style scoped>
@import '../../../assets/iconfont/iconfont.css';
  @media screen and (max-width:1000px) {
    .home-container {
      width: 850px;
      height: 430px;
    }
  }
  @media screen and (min-width:1000px) {
    .home-container {
      width: 850px;
      height: 650px;
    }
  }

  .home {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .home-container {
    background: #FFFFFF;
    display: flex;
    position: relative;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  }

  .home-menu {
    width: 60px;
    background-color: #F7F7F7;
    border-right: 1px solid #eeeeee;
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .menu-header {
    margin: 20px auto;
  }

  .user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    cursor: pointer;
  }

  .user-avatar:hover + .user-profile {
    display: block;
  }

  .user-profile {
    display: none;
    color: #FFFFFF;
    position: absolute;
    top: 0;
    left: 70px;
    width: 250px;
    height: 200px;
    background: #FFFFFF;
    z-index: 999;
  }

  .user-profile-main {
    border: 1px solid #EBEEF5;
    background-color: #FFF;
    color: #303133;
    border-radius: 4px;
  }

  .user-profile-header {
    padding: 18px 20px;
    border-bottom: 1px solid #EBEEF5;
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 15px;
    font-weight: bold;
  }

  .user-profile-header img {
    width: 45px;
    height: 45px;
  }

  .user-profile-info {
    display: flex;
    padding: 10px 20px;
    font-size: 14px;
    color: #666666;
    line-height: 28px;
  }

  .user-profile-info-title {
    width: 70px;
  }

  .menu-box {
    padding: 40px 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
  }

  .menu-list {
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .menu-item {
    color: #303133;
    cursor: pointer;
    height: 56px;
    position: relative;
  }

  .menu-unread {
    position: absolute;
    top: -5px;
    right: 5px;
    width: 18px;
    height: 18px;
    line-height: 18px;
    text-align: center;
    border-radius: 50%;
    background-color: #d02129;
    color: #ffffff;
  }

  .router-link-active i {
    color: #d02129 !important;
  }

  .iconfont {
    padding: 15px;
    font-size: 28px;
    color: #606266;
    cursor: pointer;
  }

  .iconfont:active {
    color: #d02129;
  }

  .home-main {
    padding: 0;
    flex: 1;
  }

</style>
